// app 页面接口
const express = require("express");
const writeData = require("../../db/module/writeData");
const { default: axios } = require("axios");
const apiRouter = express.Router();

// 逆地理编码
apiRouter.post("/reverseGeocoding", async (req, res) => {
  try {
    let parmse = req.body;
    let amapKey = "HILBZ-6WFC3-W6T35-OWTXU-U4PDT-I7BTO";
    const url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${parmse.lat},${parmse.long}&key=${amapKey}`;
    let result = await axios.get(url);

    res.send({
      code: 20000,
      msg: "查询成功",
      data: result.data.result,
    });
  } catch (error) { }
});

// 保存问题
apiRouter.post("/addIssue", async (req, res) => {
  try {
    const params = req.body;

    let result = await writeData(params, "answerQuestions");

    res.send(result);
  } catch (error) {
    res.send({
      code: 50000,
      msg: error,
    });
  }
});

// 保存调研结果
apiRouter.post("/saveInvestigate_survey", async (req, res) => {
  try {
    const params = req.body;

    let result = await writeData(params, "brogrammer");

    res.send(result);
  } catch (error) {
    res.send({
      code: 50000,
      msg: error,
    });
  }
});



module.exports = apiRouter;
